package com.example.permissionsystem1_1.businessFunction.service.converter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.permissionsystem1_1.businessFunction.dao.entity.po.DepartmentInfoPo;
import com.example.permissionsystem1_1.businessFunction.dao.entity.po.TestPo;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentInfoReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.testReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentInfoRspModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.testRspModel.*;
import com.example.permissionsystem1_1.common.businessFunction.BaseServiceConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class DepartmentInfoServiceConverter extends BaseServiceConverter {
    //1.insert
    /**
     * 将指定的reqModel转成指定的po
     * @param reqModel
     * @return
     */
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoInsertReqModel reqModel) {
        if (reqModel == null) {
            return null;
        }
        setDefaultAttributesValue(reqModel);
        DepartmentInfoPo po=new DepartmentInfoPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    /**
     * 将dao的返回值封装的对象(不一定是po)转成对应的RspModel
     * @param resultInt
     * @return
     */
    public static DepartmentInfoInsertRspModel covertToRspModel(Integer resultInt) {
        if( resultInt == null ) {
            return null;
        }
        DepartmentInfoInsertRspModel rspModel=new DepartmentInfoInsertRspModel();
        rspModel.setResultInt(resultInt);
        return rspModel;
    }
    //2.insertBatch
//    public static List<TestPo> convertReqModelToPo(TestInsertBatchReqModel reqModel) {
//        if (reqModel == null||reqModel.getInsertBatchReqModels()==null||reqModel.getInsertBatchReqModels().size()<=0) {
//            return null;
//        }
//        List<TestInsertReqModel> testInsertReqModels=reqModel.getInsertBatchReqModels();
//        List<TestPo> pos=new ArrayList<>();
//        for (TestInsertReqModel testInsertReqModel:testInsertReqModels) {
//            pos.add(convertReqModelToPo(testInsertReqModel));
//        }
//        return pos;
//    }
//    public static TestInsertBatchRspModel covertToInsertBatchRspModel(Integer resultSum) {
//        if( resultSum == null ) {
//            return null;
//        }
//        TestInsertBatchRspModel rspModel=new TestInsertBatchRspModel();
//        rspModel.setResultSum(resultSum);
//        return rspModel;
//    }
    //3.deleteById
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoDeleteByIdReqModel reqModel) {
        if (reqModel == null) {
            return null;
        }
        DepartmentInfoPo po=new DepartmentInfoPo();
        po.setId(reqModel.getId());
        return po;
    }
    public static DepartmentInfoDeleteByIdRspModel covertToDeleteByIdRspModel(Integer resultInt) {
        if( resultInt == null ) {
            return null;
        }
        DepartmentInfoDeleteByIdRspModel rspModel=new DepartmentInfoDeleteByIdRspModel();
        rspModel.setResultInt(resultInt);
        return rspModel;
    }
    //4.deletes
//    public static TestPo convertReqModelToPo(TestDeletesReqModel reqModel) {
//        if (reqModel == null) {
//            return null;
//        }
//        TestPo po=new TestPo();
//        BeanUtils.copyProperties(reqModel, po);
//        return po;
//    }
//    public static TestDeletesRspModel covertToDeletesRspModel(Integer resultSum) {
//        if( resultSum == null ) {
//            return null;
//        }
//        TestDeletesRspModel rspModel=new TestDeletesRspModel();
//        rspModel.setResultSum(resultSum);
//        return rspModel;
//    }
    //5.deleteBatchByIds
//    public static TestPo convertReqModelToPo(TestDeleteBatchByIdsReqModel reqModel) {
//        if (reqModel == null) {
//            return null;
//        }
//        TestPo po=new TestPo();
//        po.setIds(reqModel.getIds());
//        return po;
//    }
//    public static TestDeleteBatchByIdsRspModel covertToDeleteBatchByIdsRspModel(Integer resultSum) {
//        if( resultSum == null ) {
//            return null;
//        }
//        TestDeleteBatchByIdsRspModel rspModel=new TestDeleteBatchByIdsRspModel();
//        rspModel.setResultSum(resultSum);
//        return rspModel;
//    }
    //6.updateById
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoUpdateByIdReqModel reqModel) {
        if (reqModel == null || reqModel.getId()==null) {
            return null;
        }
        setDefaultAttributesValue(reqModel);
        DepartmentInfoPo po=new DepartmentInfoPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static DepartmentInfoUpdateByIdRspModel covertToUpdateByIdRspModel(Integer resultInt) {
        if( resultInt == null ) {
            return null;
        }
        DepartmentInfoUpdateByIdRspModel rspModel=new DepartmentInfoUpdateByIdRspModel();
        rspModel.setResultInt(resultInt);
        return rspModel;
    }
    //7.updates
//    public static TestPo convertReqModelToPo(TestUpdatesReqModel reqModel) {
//        if (reqModel == null || reqModel.getByReqModel()==null || reqModel.getSetReqModel()==null) {
//            return null;
//        }
//        reqModel.setSetReqModel((TestUpdateByIdReqModel)setDefaultAttributesValue(reqModel.getSetReqModel()));
//
//        TestPo byPo=new TestPo();
//        BeanUtils.copyProperties(reqModel.getByReqModel(), byPo);
//        TestPo setPo=new TestPo();
//        BeanUtils.copyProperties(reqModel.getSetReqModel(), setPo);
//
//        TestPo po=new TestPo();
//        po.setByPo(byPo);
//        po.setSetPo(setPo);
//        return po;
//    }
//    public static TestUpdatesRspModel covertToUpdatesRspModel(Integer resultSum) {
//        if( resultSum == null ) {
//            return null;
//        }
//        TestUpdatesRspModel rspModel=new TestUpdatesRspModel();
//        rspModel.setResultSum(resultSum);
//        return rspModel;
//    }
    //8.updateBatchByIds
//    public static TestPo convertReqModelToPo(TestUpdateBatchByIdsReqModel reqModel) {
//        if (reqModel == null || reqModel.getIds()==null || reqModel.getIds().size()<=0) {
//            return null;
//        }
//        setDefaultAttributesValue(reqModel);
//        TestPo po=new TestPo();
//        BeanUtils.copyProperties(reqModel, po);
//        return po;
//    }
//    public static TestUpdateBatchByIdsRspModel covertToUpdateBatchByIdsRspModel(Integer resultSum) {
//        if( resultSum == null ) {
//            return null;
//        }
//        TestUpdateBatchByIdsRspModel rspModel=new TestUpdateBatchByIdsRspModel();
//        rspModel.setResultSum(resultSum);
//        return rspModel;
//    }
    //9.selectById
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoSelectByIdReqModel reqModel) {
        if (reqModel == null || reqModel.getId()==null) {
            return null;
        }
        DepartmentInfoPo po=new DepartmentInfoPo();
        po.setId(reqModel.getId());
        return po;
    }
    public static DepartmentInfoSelectByIdRspModel covertToSelectByIdRspModel(DepartmentInfoPo po) {
        if( po == null ) {
            return null;
        }
        DepartmentInfoSelectByIdRspModel rspModel=new DepartmentInfoSelectByIdRspModel();
        BeanUtils.copyProperties(po, rspModel);
        return rspModel;
    }
    //10.selects
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoSelectsReqModel reqModel) {
        if (reqModel == null) {
            reqModel=new DepartmentInfoSelectsReqModel();
        }
        DepartmentInfoPo po=new DepartmentInfoPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static DepartmentInfoSelectsRspModel covertToSelectsModel(List<DepartmentInfoPo> pos) {
        if( pos == null || pos.size()<=0) {
            return null;
        }
        DepartmentInfoSelectsRspModel rspModel=new DepartmentInfoSelectsRspModel();
        List<DepartmentInfoSelectByIdRspModel> selectByIdRspModels=new ArrayList<>();
        for (DepartmentInfoPo po:pos) {
            selectByIdRspModels.add(covertToSelectByIdRspModel(po));
        }
        rspModel.setSelectByIdRspModels(selectByIdRspModels);
        return rspModel;
    }
    //11.selectBatchByIds
//    public static TestPo convertReqModelToPo(TestSelectBatchByIdsReqModel reqModel) {
//        if (reqModel == null || reqModel.getIds()==null || reqModel.getIds().size()<=0) {
//            return null;
//        }
//        TestPo po=new TestPo();
//        po.setIds(reqModel.getIds());
//        return po;
//    }
//    public static TestSelectBatchByIdsRspModel covertToSelectBatchByIdsModel(List<TestPo> pos) {
//        if( pos == null || pos.size()<=0) {
//            return null;
//        }
//        TestSelectBatchByIdsRspModel rspModel=new TestSelectBatchByIdsRspModel();
//        List<TestSelectByIdRspModel> selectByIdRspModels=new ArrayList<>();
//        for (TestPo po:pos) {
//            selectByIdRspModels.add(covertToSelectByIdRspModel(po));
//        }
//        rspModel.setSelectByIdRspModels(selectByIdRspModels);
//        return rspModel;
//    }
    //12.selectPage
    public static DepartmentInfoPo convertReqModelToPo(DepartmentInfoSelectPageReqModel reqModel) {
        if (reqModel == null ) {
            return null;
        }
        if(reqModel.getPageNo()==null || reqModel.getPageNo()<=0){
            reqModel.setPageNo(1l);
        }
        if(reqModel.getPageSize()==null || reqModel.getPageSize()<=0){
            reqModel.setPageSize(20l);
        }
        DepartmentInfoPo po=new DepartmentInfoPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static DepartmentInfoSelectPageRspModel covertToSelectPageModel(IPage<DepartmentInfoPo> iPagePo) {
        if( iPagePo == null || iPagePo.getRecords()==null) {
            return null;
        }
        DepartmentInfoSelectPageRspModel rspModel=new DepartmentInfoSelectPageRspModel();
        List<DepartmentInfoPo> pos=iPagePo.getRecords();
        List<DepartmentInfoSelectByIdRspModel> selectByIdRspModels=new ArrayList<>();
        if(pos.size()>0){
            for (DepartmentInfoPo po:pos) {
                selectByIdRspModels.add(covertToSelectByIdRspModel(po));
            }
        }
        IPage<DepartmentInfoSelectByIdRspModel> ipageModel=new Page<>(iPagePo.getCurrent(),iPagePo.getSize(),iPagePo.getTotal());
        ipageModel.setRecords(selectByIdRspModels);
        rspModel.setSelectByIdPageRspModels(ipageModel);
        return rspModel;
    }



}
